package com.gk.javaservice.util.time;

import java.text.DecimalFormat;

public class SecondsToTimeConverter {
    public static String convertSecondsToTimeFormat(String secondsAsString) {
        int totalSeconds;
        try {
            totalSeconds = Integer.parseInt(secondsAsString);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Invalid input, expecting a number of seconds.");
        }

        int days = totalSeconds / (24 * 3600);
        int remainingHours = (totalSeconds % (24 * 3600)) / 3600;
        int minutes = (totalSeconds % 3600) / 60;
        int seconds = totalSeconds % 60;

        DecimalFormat df = new DecimalFormat("00");

        StringBuilder result = new StringBuilder();
        if (days > 0) {
            result.append(days).append("天");
        }
        result.append(df.format(remainingHours)).append("时").append(df.format(minutes)).append("分").append(df.format(seconds)).append("秒");

        return result.toString();
    }

    public static void main(String[] args) {
        String secondsAsString = "933120"; // 10天12小时
        String formattedTime = convertSecondsToTimeFormat(secondsAsString);
        // System.out.println(formattedTime);
    }
}
